package multithreading.homework.Money;

public class User {
     double money;
     String idcar;

    public User(double money, String idcar) {
        this.money = money;
        this.idcar = idcar;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {

        this.money = money;
    }
    public void get(double moneyy){
        //线程名字设置为name
        String name=Thread.currentThread().getName();
        //程序锁一次只允许一个"”字符串进入
//        synchronized ("")
        synchronized (idcar)
        {
            if (this.money>=moneyy) {
                System.out.println(name+"取钱");
                setMoney(getMoney()-moneyy);
                System.out.println(name+"取了"+moneyy+"还剩"+getMoney());
            }
            else {
                System.out.println("钱不够");
                System.out.println(getMoney());

            }
        }
    }
    public String getidcar() {
        return idcar;
    }

    public User() {
    }


    public void setName(String idcar) {
        this.idcar = idcar;
    }


}

